<template>
  <div class="wrapper ">
    <swiper :options="swiperOption" ref="mySwiper" v-if="show">
      <swiper-slide v-for="item of list" :key="item.id">
          <img class="swiper-img" :src="item.imgUrl"/>
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        // 定义为显示加载图片的小点点
        pagination: '.swiper-pagination',
        loop: true,
        autoplay: 3000
      }
    }
  },
  computed: {
    show: function () {
      return this.list.length
    }
  }
}
</script>

<!--scoped表示只针对当前页面-->
<style lang="stylus" scoped>
  /*解决因为swiper是其他组件，我们无法修改其类样式，所以我们使用组件穿透的形式来进行赋值指定的class样式*/
  .wrapper >>> .swiper-pagination-bullet-active
    background: #ffffff !important
  /*解决加载图片时因为加载时此div为空加载的问题*/
  .wrapper
    width: 100%;
    overflow hidden;
    height: 0;
    padding-bottom: 30.5%;
    /*到这里结束*/
    .swiper-img
      width: 100%;
</style>
